package com.sinoatma.physignsmonitor.view

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.widget.TextView
import com.sinoatma.physignsmonitor.R

/**
 * @ProjectName : NewConsultation
 * @Author :
 * @Time : 2023/10/17 13:32
 * @Description : 文件描述
 */
class LoadProgressDialog @JvmOverloads constructor(context: Context) : Dialog(context!!, R.style.LoadProgressDialog) {
    lateinit var msgData: String
    lateinit var textView: TextView

    // 新增变量，用于存储自动关闭的延迟时间（单位：毫秒）
    private var autoCloseDelayMillis: Long = 0
    fun setMessage(message: String) {
        show()
        this.msgData = message

        handler.sendEmptyMessageDelayed(0,200)
    }

    fun getMessage(): String {
        return msgData
    }
    // 合并后的函数，传入消息内容和自动关闭的秒数
    fun showWithAutoClose(message: String, autoCloseSeconds: Int) {
        msgData = message
        show()
        handler.sendEmptyMessageDelayed(0, 200)

        autoCloseDelayMillis = autoCloseSeconds * 1000L
        // 启动自动关闭的延迟任务
        val closeHandler = Handler()
        closeHandler.postDelayed({
            dismiss()
        }, autoCloseDelayMillis)
    }





    var handler = Handler { msg ->
        textView!!.text = msgData
        false
    }






    @SuppressLint("ResourceType")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_loadprogress)
        textView = findViewById(R.id.tv_message)
        setCancelable(false)
        setCanceledOnTouchOutside(false)
    }
}